package com.ccs.word

import scala.io.Source
import java.io.{File, PrintWriter}

/**
 * Created by cm2316 on 1/9/14.
 */
class WordDeal{

}

object WordDeal{
  def readFile(fileName:String)={
    Source.fromFile(fileName)
              .getLines
              .toList
              .map(_.trim)
              .filter(_.length>0)
              .distinct
              .sortBy(_.toLowerCase())
  }

  def withPrintWriter1(saveFilePath:String)(op:PrintWriter => Unit){
    val writer = new PrintWriter(new File(saveFilePath))
    try{
      op(writer)
    }finally {
      writer.close
    }
  }

  def main (args: Array[String]) {
    val result = WordDeal.readFile("/Users/cm2316/develop/workspace/ee/word/src/main/resources/read/temp.txt")
//    println(result)
    result.foreach(word=>
      println(word)
    )
//    val saveFilePath = "/Users/cm2316/develop/workspace/ee/word/src/main/resources/read/readWord03.txt"
//    withPrintWriter1(saveFilePath){
//      //函数参数
//      //writer => writer.println(new java.util.Date)
//      writer =>
//      result.foreach(writer.println(_))
//
//    }
  }

}
